package com.soyotec.algorithm.util;

import com.soyotec.algorithm.context.OptAlgorithmContext;
import com.soyotec.algorithm.problem.Problem;
import com.soyotec.algorithm.solution.Solution;
import org.ehcache.Cache;
import org.ehcache.PersistentCacheManager;

public class SolutionCache {

    private PersistentCacheManager persistentCacheManager;
    private Cache<Integer, Solution> solutionCache;
    private Problem problem;

    public SolutionCache(OptAlgorithmContext optAlgorithmContext){
//        this(optAlgorithmContext,100,100,40);
    }

    public SolutionCache(OptAlgorithmContext optAlgorithmContext, Integer heapSize, Integer offheapSize, Integer diskSize){
//        String path = optAlgorithmContext.getWorkDir().getAbsoluteFile() + File.separator +"algorithmCache";
//        persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
//                .with(CacheManagerBuilder.persistence(path))
//                .withCache("algorithmCache",
//                        CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, Solution.class,
//                                ResourcePoolsBuilder.newResourcePoolsBuilder()
//                                        .heap(heapSize, EntryUnit.ENTRIES)  //堆  100
//                                        .offheap(offheapSize, MemoryUnit.MB)    //堆外100
//                                        .disk(diskSize, MemoryUnit.GB)      //磁盘40
//                        )
//                ).build(true);
//
//        solutionCache  = persistentCacheManager.getCache("algorithmCache", Integer.class, Solution.class);
    }

    public void put(Integer key,Solution value){
//        solutionCache.put(key,value);
    }

    public Solution get(Integer key){
//        return solutionCache.get(key);
        return null;
    }

    public void destory(){
//        persistentCacheManager.removeCache("algorithmCache");
//        persistentCacheManager.close();
//
//        try {
//
//            persistentCacheManager.destroyCache("algorithmCache");
//
//        } catch (CachePersistenceException e) {
//            e.printStackTrace();
//        }
//        try {
//            persistentCacheManager.destroyCache("algorithmCache");
//            persistentCacheManager.destroy();
//        } catch (CachePersistenceException e) {
//            e.printStackTrace();
//        } catch (Exception e){
//            e.printStackTrace();
//        }
    }

}



